﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CXW.Core.Sharp
{
    class LanguageHelper
    {
        public static string GetText(Codon codon) { return codon == null ? "" : GetText(codon, codon.Id); }
        public static string GetText(Codon codon, string defaultText)
        {
            string text = defaultText, language;
            if (codon != null)
            {
                language = codon.Properties["language"];
                if (string.IsNullOrWhiteSpace(language) || (text = ResourceService.GetString(language)) == language)
                {
                    if ((text = ResourceService.GetString(codon.Id)) == codon.Id)
                    {
                        if (string.IsNullOrWhiteSpace(text = codon.Properties["label"]))
                        {
                            text = defaultText;
                        }
                    }
                }
            }
            return text;
        }
        public static string GetText(IViewContent viewContent)
        {
            return GetText(viewContent, viewContent.Label);
        }
        public static string GetText(IViewContent viewContent, string defaultText)
        {
            string text = defaultText, language;
            if (viewContent != null)
            {
                language = viewContent.Language;
                if (string.IsNullOrWhiteSpace(viewContent.Language) || (text = ResourceService.GetString(viewContent.Language)) == language)
                {
                    if ((text = ResourceService.GetString(viewContent.CodonId)) == viewContent.CodonId)
                    {
                        if (string.IsNullOrWhiteSpace(text = viewContent.Label))
                        {
                            text = defaultText;
                        }
                    }
                }
            }
            return text;
        }

    }
}
